package com.ruoyi.project.shop.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.shop.domain.LitemallStorage;
import com.ruoyi.project.shop.service.ILitemallStorageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 文件存储Controller
 * 
 * @author ruoyi
 * @date 2020-03-11
 */
@RestController
@RequestMapping("/shop/storage")
public class LitemallStorageController extends BaseController
{
    @Autowired
    private ILitemallStorageService litemallStorageService;

    /**
     * 查询文件存储列表
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(LitemallStorage litemallStorage)
    {
        startPage();
        List<LitemallStorage> list = litemallStorageService.selectLitemallStorageList(litemallStorage);
        return getDataTable(list);
    }

    /**
     * 导出文件存储列表
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:export')")
    @Log(title = "文件存储", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LitemallStorage litemallStorage)
    {
        List<LitemallStorage> list = litemallStorageService.selectLitemallStorageList(litemallStorage);
        ExcelUtil<LitemallStorage> util = new ExcelUtil<LitemallStorage>(LitemallStorage.class);
        return util.exportExcel(list, "storage");
    }

    /**
     * 获取文件存储详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(litemallStorageService.selectLitemallStorageById(id));
    }

    /**
     * 新增文件存储
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:add')")
    @Log(title = "文件存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LitemallStorage litemallStorage)
    {
        return toAjax(litemallStorageService.insertLitemallStorage(litemallStorage));
    }

    /**
     * 修改文件存储
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:edit')")
    @Log(title = "文件存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LitemallStorage litemallStorage)
    {
        return toAjax(litemallStorageService.updateLitemallStorage(litemallStorage));
    }

    /**
     * 删除文件存储
     */
    @PreAuthorize("@ss.hasPermi('shop:storage:remove')")
    @Log(title = "文件存储", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(litemallStorageService.deleteLitemallStorageByIds(ids));
    }
}
